package com.kdg.javaEight;

import java.util.Optional;
import java.util.stream.Collectors;

/**
 * Created by kong on 2017/9/1.
 */
public class TestApi {
    public static void main(String[] args) {
        String join = String.join(":", "kk", "dd", "gg");
        System.out.println(join);
        String collect = "kkddggkkddff".chars()
                .distinct()
                .mapToObj(c -> String.valueOf((char) c))
                .sorted()
                .collect(Collectors.joining(","));
        System.out.println(collect);

        long maxUnsignedInt = (1l << 32) -1;
        String string = String.valueOf(maxUnsignedInt);
        System.out.println(maxUnsignedInt);
        int i = Integer.parseUnsignedInt(string, 10);
        String string2 = Integer.toUnsignedString(i, 10);
        System.out.println(string2);

//        System.out.println(new Province().getZoo().getAnimal());
        //避免了上面的空指针  利用 Java 8 的 Optional 类型来摆脱所有这些 null 检查
        Optional.of(new Province())
                .map(Province::getZoo)
                .map(Zoo::getAnimal)
                .map(Animal::getName)
                .ifPresent(System.out::println);

    }
}

class Province{
    Zoo zoo;

    public Zoo getZoo() {
        return zoo;
    }

    public void setZoo(Zoo zoo) {
        this.zoo = zoo;
    }
}
class Zoo{
    Animal animal;

    public Animal getAnimal() {
        return animal;
    }

    public void setAnimal(Animal animal) {
        this.animal = animal;
    }
}
class Animal{
    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}